package com;

import java.util.ArrayList;

import sun.jdbc.rowset.CachedRowSet;
import util.mysql;
import util.oracle;

public class pinglun {
	public static void main(String args[]) {
		oracle o = new oracle();
		mysql m = new mysql();
		try {
			int all = 0;
			long start = System.currentTimeMillis();
			CachedRowSet count = o
					.executeQuery("select count(id) as count from pinglun");
			if (count.next()) {
				all = count.getInt("count");
			}
			ArrayList <String>list= new ArrayList<String>();
			for(int a=1,b=1;a<=all;a++){
				if(a%3000==0||a==all){
					
					list.clear();
					String sql="select t.* from(select a.*,rownum rn from pinglun a )t where t.rn>="+b+" and t.rn<="+a;
					CachedRowSet rs= o.executeQuery(sql);
					while(rs.next()){
						list.add("INSERT INTO `pinglun` VALUES ("+get(rs.getString(1))+","+get(rs.getString(2))+","+get(rs.getString(3))+","+get(rs.getString(4))+","+get(rs.getString(5).trim().substring(0,19))+","+get(rs.getString(6))+","+get(rs.getString(7))+","+get(rs.getString(8))+","+get(rs.getString(9))+","+get(rs.getString(10))+")");
					}
					m.execute(list);
					System.err.println("从 "+b +"  到  "+a);
					b=a+1;
				}
				
			}
			System.err.println("用时：" + (System.currentTimeMillis() - start));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String get(String s) {
		if (s == null || s.trim().equalsIgnoreCase("null")) {
			return null;
		} else {
			return "'" + s.replaceAll("'", "''").replaceAll("\\\\","\\\\\\\\")+ "'";
		}
	}
}
